#include <vector>
#include <cmath>
#include "force.cpp"

using namespace std;

class forceContainer: public std::vector<force>
{
    public:
        void newForce(locvar, locvar, bool, bool);
        
        void updateNetForce();
        void checkForce();
        void removeForce(unsigned, bool);
        
        force netForce;
};

void forceContainer::newForce(locvar x, locvar y, bool refresher, bool updater)
{
    force localForce(x, y, refresher);    

    push_back(localForce);
    
    if (updater) { updateNetForce(); }
}


void forceContainer::updateNetForce()
{
    netForce.x = 0;
    netForce.y = 0;
    for ( unsigned c = 0; c < size(); c++ )
    {
        netForce.x += at(c).x;
        netForce.y += at(c).y;
    }
}

void forceContainer::checkForce()
{
    for ( unsigned c = 0; c < size(); c++ )
    {
        if (at(c).refresher) { removeForce(c,false); }
    }
}

void forceContainer::removeForce(unsigned id, bool updater)
{
    erase(begin()+id);
    if (updater) { updateNetForce(); }
}
